package com.nsl.my_youlai;

import com.nsl.my_youlai.mystar.NslUtilUuid;
import org.apache.commons.codec.digest.Md5Crypt;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import static com.nsl.my_youlai.mystar.NslUtilBinaryConversion.bytesToHex;

public class Common {


    @Test
    public void testDemo1(){
        String filePath="/D:/Java_Projects/IntelliJ_IDEA-2022.2.3/Gitee/my_loulai/target/classes/docx/设计模板(Demo).docx";
        File file=new File(filePath);
        System.out.println(file.exists());
    }

    @Test
    public void md5() throws NoSuchAlgorithmException {
        String message="abc";
        System.out.println(Md5Crypt.apr1Crypt(message).length());
        // 创建MD5消息摘要对象
        MessageDigest md = MessageDigest.getInstance("MD5");

        // 计算消息的摘要
        byte[] digest = md.digest(message.getBytes());

        // 将摘要转换为十六进制字符串
        String hexString = bytesToHex(digest);
        System.out.println(hexString);
        System.out.println(hexString.length());

    }

    @Test
    public void uuid(){
        System.out.println(NslUtilUuid.generateUuidWithOutHyphen());
        System.out.println(NslUtilUuid.generateUuidWithOutHyphen().length());
        System.out.println(NslUtilUuid.generateUuidWithOutHyphen().replace("-", ""));

        String filePath="d:\\abc\\test1.txt";

        File saveFile=new File(filePath);
        System.out.println(saveFile.getPath());

        String path=saveFile.getPath();
        File saveFileDir=new File(path.substring(0,path.lastIndexOf(File.separator)));
        if(!saveFileDir.exists()){
            saveFileDir.mkdirs();
        }
    }


    @Test
    public void demox1() throws UnsupportedEncodingException {
        String fileName= "填充信息表格_v1 - 安阳.xlsx";
        String s=URLEncoder.encode(fileName, "utf-8");
        System.out.println(s);
    }

    @Test
    public void demo2(){
        System.out.println("communication station".toUpperCase().replace(" ","_"));
    }


}
